package com.ja.openchat.adapters;

import android.text.TextUtils;
import android.widget.CheckBox;

import com.amap.api.services.core.PoiItem;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.BaseLoadMoreModule;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ja.openchat.R;
import com.ja.openchat.data.NotShowPoiItem;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ChooseLocationAdapter extends BaseQuickAdapter<PoiItem, BaseViewHolder> implements LoadMoreModule {

    public void setSelectPoiItem(PoiItem poiItem) {
        this.choosePoiItem = poiItem;
    }
    private PoiItem choosePoiItem = null;


    public ChooseLocationAdapter(@Nullable List<PoiItem> data) {
        super(R.layout.item_choose_location_info, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, PoiItem poiItem) {
        CheckBox checkBox = holder.getView(R.id.check_box);
        boolean isEqual = false;
        if (choosePoiItem!=null&&choosePoiItem.getLatLonPoint().equals(poiItem.getLatLonPoint())) {
            if(choosePoiItem.getLatLonPoint().getLatitude() == 0&&choosePoiItem.getLatLonPoint().getLongitude() == 0){
                isEqual = true;
            }else{
                if(!TextUtils.isEmpty(choosePoiItem.getTitle())&&choosePoiItem.getTitle().equals(poiItem.getTitle())){
                    isEqual = true;
                }else{
                    isEqual = false;
                }
            }
        }
        checkBox.setChecked(isEqual);
        if(poiItem instanceof NotShowPoiItem){
            holder.setGone(R.id.tv_message,true);
            holder.setText(R.id.tv_title,getContext().getString(R.string.do_not_show_location));
        }else{
            holder.setGone(R.id.tv_message,false);
            holder.setText(R.id.tv_title,poiItem.getTitle());
            holder.setText(R.id.tv_message,poiItem.getProvinceName() + poiItem.getCityName() + poiItem.getAdName() + poiItem.getSnippet());
        }

    }

    @Override
    public @NotNull BaseLoadMoreModule addLoadMoreModule(@NotNull BaseQuickAdapter<?, ?> baseQuickAdapter) {
        return new BaseLoadMoreModule(baseQuickAdapter);
    }
}
